
package com.hexinfo.dmpro.script.publish.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hexinfo.dmpro.script.publish.dao.ScriptPublishResultMapper;
import com.hexinfo.dmpro.script.publish.entity.ScriptPublishResultEntity;
import com.hexinfo.dmpro.script.publish.service.IScriptPublishResultService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 脚本发布清单
 *
 * @author Wang zhihao
 * @date 2023-09-13 18:17:51
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ScriptPublishResultServiceImpl extends ServiceImpl<ScriptPublishResultMapper, ScriptPublishResultEntity> implements IScriptPublishResultService {

    private final ScriptPublishResultMapper scriptPublishResultMapper;

    @Override
    public Page queryList(Page page, ScriptPublishResultEntity scriptPublishResult) {
        LambdaQueryWrapper<ScriptPublishResultEntity> wrapper = Wrappers.lambdaQuery();
        Page returnPage = this.baseMapper.selectPage(page, wrapper);
        return returnPage;
    }

    /**
     * @Method queryListNoPage
     * @Param
     * @param scriptPublishResult
     * @Return java.util.List<com.hexinfo.dmpro.script.publish.entity.ScriptPublishResultEntity>
     * @Description 不分页查询
     * @Author Wang zhihao
     * @Date 2023/11/10 13:28
     * @Version V1.0
     */
    @Override
    public List<ScriptPublishResultEntity> queryListNoPage(ScriptPublishResultEntity scriptPublishResult) {
        LambdaQueryWrapper<ScriptPublishResultEntity> wrapper = beforeQuery(scriptPublishResult);
        return this.baseMapper.selectList(wrapper);
    }

    /**
     * @Method removeByListId
     * @Param
     * @param listPkId
     * @Return void
     * @Description 根据listId删除
     * @Author Wang zhihao
     * @Date 2023/11/13 16:52
     * @Version V1.0
     */
    @Override
    public void removeByListId(String listPkId) {
        scriptPublishResultMapper.removeByListId(listPkId);
    }

    /**
     * @Method beforeQuery
     * @Param
     * @param scriptPublishResult
     * @Return com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<com.hexinfo.dmpro.script.publish.entity.ScriptPublishListEntity>
     * @Description 搜索前置
     * @Author Wang zhihao
     * @Date 2023/11/10 13:34
     * @Version V1.0
     */
    private LambdaQueryWrapper<ScriptPublishResultEntity> beforeQuery(ScriptPublishResultEntity scriptPublishResult) {
        LambdaQueryWrapper<ScriptPublishResultEntity> wrapper = Wrappers.lambdaQuery();
        if (StrUtil.isNotBlank(scriptPublishResult.getScriptPublishListId())) {
            wrapper.eq(ScriptPublishResultEntity::getScriptPublishListId, scriptPublishResult.getScriptPublishListId());
        }
        return wrapper;
    }

}
